{% extends 'base.html' %}
{% block title %}定时任务{% endblock %}
{% block content %}
<div class="span9" id="content">
    <div class="block">
        <div class="navbar navbar-inner block-header">
            <div class="muted pull-left">任务</div>
        </div>
        <h4>{{ msg }}</h4>
        {% if messages %}
        <div class="messages" style="margin-left: 10px">
            {% for message in messages %}
            <p {% if message.tags %} class="{{ message.tags }}" {% endif %}
               style="color:red">{{ message }}</p>
            {% endfor %}
        </div>
        {% endif %}
        <div class="block-content collapse in">
            <div class="span12">
                <div class="table-toolbar">
                    <div class="btn-group">
                        <a href="{% url 'addting' %}">
                            <input class="btn btn-success" type="button" value="添加">
                        </a>
                    </div>
                </div>
                <div id="example2_wrapper" class="dataTables_wrapper form-inline" role="grid">
                    <div class="row">
                        <div class="span6">
                        </div>
                    </div>
                    <table cellpadding="0" cellspacing="0" border="0"
                           class="table table-hover table table-striped table-bordered dataTable" id="example2"
                           aria-describedby="example2_info">
                        <thead>
                        <tr role="row">
                            <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="example2"
                                rowspan="1" colspan="1" aria-sort="ascending"
                                aria-label="Rendering engine: activate to sort column descending"
                                style="width: 168px;">所属项目
                            </th>
                            <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="example2"
                                rowspan="1" colspan="1" aria-sort="ascending"
                                aria-label="Rendering engine: activate to sort column descending"
                                style="width: 168px;">任务名称
                            </th>
                            <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="example2"
                                rowspan="1" colspan="1" aria-sort="ascending"
                                aria-label="Rendering engine: activate to sort column descending"
                                style="width: 168px;">任务用例
                            </th>
                            <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="example2"
                                rowspan="1" colspan="1" aria-sort="ascending"
                                aria-label="Rendering engine: activate to sort column descending"
                                style="width: 168px;">类型
                            </th>
                            <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="example2"
                                rowspan="1" colspan="1" aria-sort="ascending"
                                aria-label="Rendering engine: activate to sort column descending"
                                style="width: 168px;">用例类型
                            </th>
                            <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="example2"
                                rowspan="1" colspan="1" aria-sort="ascending"
                                aria-label="Rendering engine: activate to sort column descending"
                                style="width: 168px;">执行时间
                            </th>
                            <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="example2"
                                rowspan="1" colspan="1" aria-sort="ascending"
                                aria-label="Rendering engine: activate to sort column descending"
                                style="width: 168px;">执行状态
                            </th>
                            <th class="sorting" role="columnheader" tabindex="0" aria-controls="example2"
                                rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending"
                                style="width: 233px;">创建者
                            </th>
                            <th class="sorting" role="columnheader" tabindex="0" aria-controls="example2"
                                rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending"
                                style="width: 214px;">操作
                            </th>
                        </thead>
                        <tbody role="alert" aria-live="polite" aria-relevant="all">
                        {% for project in timingtasks %}
                        <tr class="gradeA odd" id="{{ project.id }}">
                            {% if project == None %}
                            <p style="    color: red;"> 你所属于的项目是不是没有测试任务，你可以选择去添加所属的项目的测试任务</p>
                            {% else %}
                        <tr class="gradeA odd">
                            <td class=" sorting_1">{{ project.prject }}</td>
                            <td class=" sorting_1">{{ project.name }}</td>
                            <td class=" sorting_1">{{ project.tasktyped }}</td>
                            <td class=" sorting_1">{{ project.casetype }}</td>
                            <td class=" sorting_1">{% for case in project.case.all %} {{ case.casenum }}
                                、{% endfor %}
                            </td>
                            <td class=" sorting_1">{{ project.taskstart }}</td>

                            {% if project.tasktyped == '一次性任务' %}
                            {% if project.yunxing_status == "创建" %}
                            <td class=" sorting_1">
                                <span>创建</span>
                            </td>
                            {% elif project.yunxing_status == "运行" %}
                            <td class=" sorting_1">
                                <span>执行中</span>
                            </td>
                            {% elif project.yunxing_status == "完成" %}
                            <td class=" sorting_1">
                                <span>完成</span>
                            </td>
                            {% endif %}
                            {% else %}

                            {% if project.yunxing_status == "创建" %}
                            <td class=" sorting_1">
                                <button class="btn btn-primary " onclick="runtask({{ project.id}})">执行
                                </button>
                            </td>
                            {% elif project.yunxing_status == "运行" %}
                            <td class=" sorting_1">
                                <button class="btn btn-primary " onclick="runtask({{ project.id}})">暂停
                                </button>
                            </td>
                            {% elif project.yunxing_status == "暂停" %}
                            <td class=" sorting_1">
                                <button class="btn btn-primary " onclick="runtask({{ project.id}})">恢复
                                </button>
                            </td>
                            {% endif%}
                            {% endif %}
                            <td class=" ">{{ project.makeuser }}</td>
                            <td class=" ">
                                {% if project.tasktyped == '一次性任务' %}
                                <button class="btn btn-danger "
                                        onclick="deletetimingtask({{ project.id }})">
                                    <i class="icon-remove icon-white"></i>
                                    删除
                                </button>
                                {% else %}
                                <a href="{% url 'edittiming' id=project.id %}">
                                    <button class="btn btn-primary ">
                                        <i class="icon-pencil icon-white"></i>编辑
                                    </button>
                                </a>
                                <button class="btn btn-danger "
                                        onclick="deletetimingtask({{ project.id }})">
                                    <i class="icon-remove icon-white"></i>
                                    删除
                                </button>
                                {% endif %}
                            </td>
                        </tr>
                        {% endif %}
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block js %}
function deletetimingtask(id) {
$.ajax({
url:'{% url 'tingtask' %}',
type:'DELETE',
data:id,
contentType: 'application/json; charset=UTF-8',
processData:false,
success:function(data){
if(data['code']!=2){
alert(data['data'])
}else{
alert(data['data'])
window.location.reload()


}
}
})
}
function runtask(id){
$.ajax({
url:'/timk_opear/?id='+id,
type:'GET',
contentType: 'application/json; charset=UTF-8',
processData:false,
success:function(data){
if(data['code']!=0){
alert(data['data'])
}else{
alert(data['data'])
window.location.reload()
}
}
})

}
{% endblock %}
